<!DOCTYPE html>
<html>
<head>
	<title>Prospecting Manager</title>
</head>
<body>
	<h1 align="center">List of Planets</h1>
		<?php
		
			//Include of required files
			require_once ("constants.php");
			require_once ("planets_class.php");
		?>
<!--
		Prepares the planets table header
-->
		<table WIDTH="50%" border="1" RULES="ALL" FRAME="BOX" align="center" cellspacing="0" cellpadding="0">
			<tr align="center" valign="center">
				<th>Planet Name</th>
				<th>Planet Size</th>
				<th colspan="2">Deposits</th>
			</tr>
			<?php
				//If there is planet data
				if( $PlanetData = planets::ListAllPlanets() ) {

					/* Display each planet in a row of the table: name, size and two buttons: one to go to the
					 * "deposits list" view and another to go to the "deposits map" view 
					 * it sends planet_name, planet_size and planet_id with the post method
					 */
					foreach($PlanetData as $Planet){
						echo "<tr align=\"center\" valign=\"center\">\n";
						echo "<td>".$Planet['name']."</td><td>".$Planet['size']."x".$Planet['size']."</td>";
						echo "<td><p><FORM METHOD=\"post\" ACTION=\"listDepos.php\">\n";
						echo "<input type=\"hidden\" name=\"planet_id\" value=".$Planet['id'].">\n";
						echo "<input type=\"hidden\" name=\"planet_name\" value=".$Planet['name'].">\n";
						echo "<input type=\"hidden\" name=\"planet_size\" value=".$Planet['size'].">\n";
						echo "<input type=\"submit\" value=\"List View\" name=\"editar\">\n";
						echo "</FORM></p></td>\n";
						echo "<td><p><FORM METHOD=\"post\" ACTION=\"mapDepos.php\">\n";
						echo "<input type=\"hidden\" name=\"planet_id\" value=".$Planet['id'].">\n";
						echo "<input type=\"submit\" value=\"Map View\" name=\"editar\">\n";
						echo "</FORM></p></td>\n";
						echo "</tr>\n";
					}
				}
			?>
		</table>
<!--
		Link to the "create planet" script
-->
	<br>
	<p align="center"><b><a href="allDepos.php">View all Deposits</a></b></p>
<!--
		Link to the "all deposits" script
-->
	<br>
	<p align="center"><a href="insert_pl.php">Create new Planet</a></p>
</body>
</html>
